from socket import *
import pickle
def PadMsg(msg):
    while len(msg) < 1024:
        msg=msg+' '
    return msg


myHost = ''                           
myPort = 50007                       

sockobj = socket(AF_INET, SOCK_STREAM)     
sockobj.bind((myHost, myPort))            
sockobj.listen(5)                        
video = open('/home/zank/Desktop/tcc2/DESENVOLVIMENTO/provider/lost.avi', 'r')
Saida=False
while 1:                                   
    connection, address = sockobj.accept() 
    print 'Server connected by', address   
    data = connection.recv(1024)
    print data
    if data.strip() == 'PLAY':
	count = 0
	while 1:
	    for stream in video.readlines():
		#count = count+1
		#chunk = openfile('chunkfile','w')
		#data = [count,stream]
		#pickle.dump(data,chunk)
		#chunk.close

		#chunktosend = open('chunkfile')
		#for line in chunktosend.readlines():
		#    connection.send(line)

		connection.send(stream)
		#chunktosend.close()
		
	        #data = struct.pack('i'+tam+'s',count,stream)
		#connection.send(data)

    else:
	pass
